package com.haha.json;

/**
 * Created by Administrator on 2016/7/12.
 */
import android.graphics.Bitmap;
import android.util.Log;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class BitmapUtils {

    /***
     * 保存Bitmap到本地
     */
    public static boolean saveBitmap(Bitmap bitmap, String filePathName, boolean overwrite){
        File file = new File(filePathName);
        if (file.exists()) {
            if(overwrite) file.delete();
            else {
                Log.e("SamLog","saveBitmap >> file" +filePathName +" already exists!");
                return false;
            }
        }
        FileOutputStream fOut = null;
        try {
            fOut = new FileOutputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return false;
        }
        bitmap.compress(Bitmap.CompressFormat.PNG, 90, fOut);
        try {
            fOut.flush();
            fOut.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }

}
